package com.htc.callcare.model;

import java.util.Date;

import com.htc.callcare.infrastructure.globalVar;

public class VoiceMailModel implements Comparable<VoiceMailModel> {
	public int id;
	// 1 Yes -0No
	public int isNew;
	public String callTime;
	public String callDay;
	public String callNumber;
	//public int isCheck;
	public String fileUri;
	// 1-is separator 0-is no separator
	public int separator;
	public Date date;

	public VoiceMailModel(String callDay, int separator) {
		super();
		this.callDay = callDay;
		this.separator = separator;
	}

	public VoiceMailModel(String fileUri) {
		super();
		this.fileUri = fileUri;
		String raw = "";
		try {
			String[] temp = removeExtension(fileUri, raw).split("_");
			this.callTime = temp[1].replace("h", ":");
			this.callDay = temp[2];
			this.callNumber = temp[3];
			this.separator = 0;

		} catch (Exception e) {
			this.callTime = "00:00";
			this.callDay = "2000-1-1";
			this.callNumber = "0909090909";
			this.separator = 0;
			removeExtension(fileUri, raw);
		}

		this.date = new Date(Integer.parseInt(this.callDay.split("-")[0]),
				Integer.parseInt(this.callDay.split("-")[1]),
				Integer.parseInt(this.callDay.split("-")[2]),
				Integer.parseInt(this.callTime.split(":")[0]),
				Integer.parseInt(this.callTime.split(":")[1]));
	}

	public String removeExtension(String fileUri, String raw) {
		if (fileUri.endsWith(globalVar.amrType)) {
			raw = fileUri.replace(globalVar.amrType, "");
		} else if (fileUri.endsWith(globalVar.mp4Type)) {
			raw = fileUri.replace(globalVar.mp4Type, "");
		} else if (fileUri.endsWith(globalVar.three_gppType)) {
			raw = fileUri.replace(globalVar.three_gppType, "");
		}
		return raw;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getIsNew() {
		return isNew;
	}

	public void setIsNew(int isNew) {
		this.isNew = isNew;
	}

	public String getCallTime() {
		return callTime;
	}

	public void setCallTime(String callTime) {
		this.callTime = callTime;
	}

	public String getCallDay() {
		return callDay;
	}

	public void setCallDay(String callDay) {
		this.callDay = callDay;
	}

	public String getCallNumber() {
		return callNumber;
	}

	public void setCallNumber(String callNumber) {
		this.callNumber = callNumber;
	}

/*	public int getIsCheck() {
		return isCheck;
	}

	public void setIsCheck(int isCheck) {
		this.isCheck = isCheck;
	}*/

	public String getFileUri() {
		return fileUri;
	}

	public void setFileUri(String fileUri) {
		this.fileUri = fileUri;
	}

	public int getSeparator() {
		return separator;
	}

	public void setSeparator(int separator) {
		this.separator = separator;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	@Override
	public int compareTo(VoiceMailModel another) {
		// TODO Auto-generated method stub
		int reuslt = 0;
		try {
			reuslt = date.compareTo(another.date);
		} catch (NullPointerException e) {
			// TODO: handle exception
		}
		if (reuslt > 0) {
			return -1;
		}
		if (reuslt < 0) {
			return -0;
		} else {
			return 0;
		}

	}

}
